package com;

import com.xjm.controller.HelloController;
import com.xjm.service.HelloService;
import com.xjm.service.impl.HelloServiceImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;

/**
 * @author jaymin
 * 2020/11/26 23:11
 */
@Configuration
@ComponentScan(value = "com.xjm")
public class AnnotationContextDemo {
	public static void hanlde(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationContextDemo.class);
		HelloService helloService = applicationContext.getBean(HelloServiceImpl.class);
		String hello = helloService.hello();
		System.out.println(hello);
		String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
		Arrays.stream(beanDefinitionNames).forEach(System.out::println);
	}

	public static void main(String[] args) {
		ApplicationContext applicationContext = new AnnotationConfigApplicationContext(AnnotationContextDemo.class);
		HelloController helloController = applicationContext.getBean(HelloController.class);
		helloController.hello();
		String[] beanDefinitionNames = applicationContext.getBeanDefinitionNames();
		Arrays.stream(beanDefinitionNames).forEach(System.out::println);
	}
}
